﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Model.ActiveRecord;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Infrastructure.Common;

namespace Xiaov.SmartWeb.Application.PluginSrc.GuestBook.Json
{
    public partial class Subject : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int page = Request.Params["page"].ToInt32();
            int pagesize = Request.Params["rows"].ToInt32();
            string sort =Request.Params["sort"].ToRequestString();
            string c = Request.QueryString["c"].ToRequestString();
            string key = Request.QueryString["key"].ToRequestString();
            int boardId = Request.QueryString["bid"].ToInt32();
            Response.Clear();
            A_GUESTBOOK_SUBJECT subjects = new A_GUESTBOOK_SUBJECT();
            IList<A_GUESTBOOK_SUBJECT> list = new List<A_GUESTBOOK_SUBJECT>();
            if (string.IsNullOrEmpty(key))
            {
                list = A_GUESTBOOK_SUBJECT.FindAll().OrderByDescending(s => s.PUBDATE).OrderByDescending(s => s.ISTOP).ToList();
            }
            else
            {
                if (c == "TITLE")
                {
                    list = A_GUESTBOOK_SUBJECT.FindAll().Where(s => s.TITLE.Contains(key)).OrderByDescending(s => s.PUBDATE).OrderByDescending(s => s.ISTOP).ToList();
                }
                if (c == "CONTENT")
                {
                    list = A_GUESTBOOK_SUBJECT.FindAll().Where(s => s.CONTENT.Contains(key)).OrderByDescending(s => s.PUBDATE).OrderByDescending(s => s.ISTOP).ToList();
                }
            }
            if (boardId != 0)
            {
                list = list.Where(s => s.BOARDID == boardId.ToString()).ToList();
            }
            if (list.Count > 0)
            {
                Response.Write(list.ToDataTable().ToJsonForGrid());
            }
            else
            {
                Response.Write("[]");
            }
            Response.End();
        }
    }
}